/*
 * has_xxx.h
 *
 *  Created on: 2008-9-22
 *      Author: fanliangliang
 */

#ifndef HAS_XXX_H_
#define HAS_XXX_H_

struct no_tag { char x[1]; };
struct yes_tag { char x[2]; };

#if defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 4)

#define HAS_XXX_DEFINE(trait_name, return_type, name, params) \
	template <typename T> \
	class trait_name { \
	private: \
		template <return_type (T::*)params> \
		struct tester; \
		template <typename U> \
		static yes_tag test(tester<&U::name>*); \
		template <typename U> \
		static no_tag test(...); \
	public: \
		static const bool value = (sizeof(test<T>(0)) == sizeof(yes_tag)); \
	}

//template <typename T>
//struct has_f {
//	template <void (T::*)(int)>
//	struct tester;
//	template <typename U>
//	static yes_tag test(tester<&U::f>*);
//	template <typename U>
//	static no_tag test(...);
//	static const bool value = (sizeof(test<T>(0)) == sizeof(yes_tag));
//};

#else

#define HAS_XXX_DEFINE(trait_name, return_type, name, params) \
	template <typename T> \
	struct trait_name { \
		static const bool value = false; \
	}

#endif

#endif /* HAS_XXX_H_ */
